use serde::Deserialize;
use serde::Serialize;
use ts_rs::TS;
use yata::core::PeriodType;
use yata::core::ValueType;

use super::IndicatorActionWrap;

///
/// Struct to hold the results of Struct yata::indicators::RelativeVigorIndex
///
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct RVI {
    /// 2 signals
    ///Signal #1 on main value crosses signal line value.
    ///When main value crosses signal line upwards, returns full buy signal.
    /// When main value crosses signal line downwards, returns full sell signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,

    ///
    ///Signal #2 on main value crosses signal line value outside safe zone.
    ///When main value is below -zone and crosses signal line upwards, returns full buy signal.
    ///  When main value is above +zone and crosses signal line downwards, returns full sell signal.
    ///  Otherwise returns no signal.
    pub signal1: Option<IndicatorActionWrap>,

    ///2 values
    ///main value
    ///Range in [-0.5; 0.5]
    ///
    pub main: ValueType,

    ///signal line value
    ///Range in [-0.5; 0.5]
    pub signal: ValueType,
}

/// Configuration
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct RVIConfig {
    /// period1: PeriodType
    /// Summarize period. Default is 10.
    /// Range in [2; PeriodType::MAX)
    pub period1: PeriodType,
    /// period2: PeriodType
    ///SWMA period. Default is 4.
    /// Range in [2; PeriodType::MAX)
    pub period2: PeriodType,
    /// signal: M
    /// Signal line moving average type.
    ///
    /// Default is SWMA(4).
    ///
    /// Period range in [2; PeriodType::MAX)
    pub signal: PeriodType,

    ///zone: ValueType
    ///Signal zone filter. Default is 0.25.
    ///
    ///Range in [0.0; 0.5)
    pub zone: ValueType,
}

impl Default for RVIConfig {
    fn default() -> Self {
        Self {
            period1: 10,
            period2: 4,
            signal: 4,
            zone: 0.25,
        }
    }
}
